import { ref } from "vue";
import { defineStore } from "pinia";
import { getActivityList } from "@/api/wlxz/act_list";

export const useActivityStore = defineStore("activity", () => {
  // 活动对象数组 - 存储查询结果
  const activities = ref([]);

  // 查询活动列表方法 - 从activity.vue移过来
  const loadActivities = async (params = {}) => {
    try {
      const response = await getActivityList({
        pageNum: params.pageNum || 1,
        pageSize: params.pageSize || 999999999, // 这里我真的不知道了所有的都注释了，后端我也没找到谁设置10了
        ...params
      });
      if (response.code === 200) {
        activities.value = response.rows || [];
        console.log("查询活动列表",response.rows) 
        return {
          code: 200,
          data: response.rows || [],
          total: response.total || 0
        };
      } else {
        console.log(response.code);
        return {
          code: response.code,
          msg: response.msg || '获取活动列表失败',
          data: [],
          total: 0
        };
      }
    } catch (error) {
      console.error('获取活动列表失败:', error);
      console.log("错误");
      return {
        code: 500,
        msg: '网络错误，请稍后重试',
        data: [],
        total: 0
      };
    }
  };

  return {
    activities,
    loadActivities
  };
});